;(function ($) {

    let page = parseInt(GetQueryString("page")) || 1;
    let limit = parseInt(GetQueryString("limit")) || 6;
    let speciesId = GetQueryString("speciesId") || '052e89a3f93c493782967523e2f7d830';
    console.log(page, limit, speciesId);

    //文章
    $.ajax({
        url: getContextPath() + "/api/agt_article/query",
        data: {
            page: page,
            limit: limit
        },
        dataType: "json",
        async: false,
        success: function (result) {
            let div1 = $(".newsAgriList");
            $.each(result.data, function (idx, obj) {
                let divHtml = `<li class="used_agriListLi  jq22">
                  <div class="border-left" style="height: 0px;"></div>
                  <div class="border-bottom" style="width: 0px;"></div>
                  <div class="border-top" style="width: 0px;"></div>
                  <div class="border-right" style="height: 0px;"></div>
                  
                  <div class="used_agriListCon">
                    <div class="used_agriListConLeft">
                      <img class="img-responsive" src="${obj.articleCover}" width="200" height="200">
                    </div>
                    <div class="used_agriListConRight">
                      <div class="used_agriListConRight_title">
                        <a href="/article/${obj.id}">
                          <h2>${obj.articleTitle}</h2>
                        </a>
                      </div>
                      <div class="used_agriListConRight_Con">
                        <a href="/article/${obj.id}">
                          <p>${obj.articleAbstract}</p>
                        </a>
                      </div>
                    </div>
                  </div>
                </li>`;
                div1.append(divHtml);
            });

            console.log(GetQueryString("page"), GetQueryString("limit"));

            let num = (result.count + limit - 1) / limit;

            //分页
            $("#Pagination").pagination(num, {
                link_to: "javascript:;",
                current_page: page - 1,
                callback: function (idx, cont) {
                    location.href = `/article?page=${idx + 1}&limit=${limit}`;
                }

            });
        }
    });

    //资讯
    $.ajax({
        url: getContextPath() + "/api/agt_article/page",
        data: {
            page: 1,
            limit: 6
        },
        dataType: "json",
        async: false,
        success: function (result) {
            let div = $(".newsAgriDetail-news-con_list");

            $.each(result.data, function (idx, obj) {
                let agtHtml = `<li>
                        <a href="/article/${obj.id}">${obj.articleTitle}</a>
                      </li>`;
                div.append(agtHtml);
            });
        }
    });

    function GetQueryString(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

/*    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);return null;
    }*/

    /**
     * 获取项目根目录
     * @returns {string}
     */
    function getContextPath() {
        let pathName = document.location.pathname;
        let index = pathName.substr(1).indexOf("/");
        let result = pathName.substr(0, index + 1);
        // console.log(pathName,index,result);
        return result;
    }

})(window.jQuery);